home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / include / psm.h < prev    next >
C/C++ Source or Header  |  1992-01-23  |  5KB  |  151 lines

  1. /* --------------------------------------------------------------------------
  2.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  3.  *
  4.  * You can use and distribute this software under the terms of the licence
  5.  * you should have received along with this program.
  6.  * If not or if you want additional information, write to
  7.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  8.  * D-7500 Karlsruhe 1, Germany.
  9.  * --------------------------------------------------------------------------
  10.  */
  11. /* persistent storage manager: header */
  12.  
  13. #ifndef PSMH
  14. #define PSMH 1
  15.  
  16. // enumeration of sos_Access_mode and sos_container_status must be in a 
  17. // fixed order (i.e. the same order), because two functions (entercontainer, access)
  18. // use this fact in  a cast construction
  19.  
  20. enum sos_Sync_mode        {WAITING, TESTING};
  21. enum sos_Open_result      {OPENED, LOCKED, UNACCESSIBLE};
  22. enum sos_Access_mode      {READING, CHECKOUT,  WRITING};
  23. enum sos_Container_status {READABLE,CHECKEDOUT,WRITEABLE,UNAVAILABLE, DESTROYED};
  24. enum sos_Existing_status  {NOT_EXISTING, PERHAPS_EXISTING};
  25.  
  26. typedef unsigned sos_Offset;
  27.  
  28. void psm_initialize(); //automatically called from C++
  29.  
  30. class sos_Object;
  31. class sos_Container_set;
  32. class sos_Container_cursor;
  33. class sos_Container;
  34.  
  35. #ifndef NO_TT
  36. extern const sos_Container _psm_checked_cnt;
  37. #endif NO_TT
  38.  
  39. // *******************************************************************************
  40.  
  41. class sos_Container
  42. {
  43.     int id; // 0<=id<2^24-1
  44.  
  45. public:
  46.    static sos_Container make (int i) {sos_Container ct; ct.id=i; return ct;}
  47.    static sos_Container create();
  48.  
  49.    operator int() const {return id;}
  50.    int operator==(sos_Container c) const {return id==c.id;}
  51.  
  52.    sos_Container_status status() const;
  53.    int modified() const;
  54.    int exists() const;
  55.    int deleted() const;
  56.    unsigned occupied() const;
  57.    sos_Existing_status object_exists(sos_Offset, unsigned) const;
  58.  
  59.    sos_Open_result open(sos_Access_mode, sos_Sync_mode) const;
  60.    sos_Open_result access(sos_Access_mode, sos_Sync_mode) const;
  61.    sos_Open_result checkout(sos_Access_mode, sos_Sync_mode) const;
  62.    void close() const;
  63.    void destroy() const;
  64.  
  65.    void commit() const;
  66.    void reset() const;
  67.    void squeeze() const;
  68.    void clear() const;
  69.  
  70.    sos_Offset allocate(unsigned size) const; // allocates rounded(size) bytes
  71.    void deallocate(sos_Offset o, unsigned size) const; //deallocates rounded(size) bytes
  72.    unsigned rounded(unsigned size) const; // rounded(size) >= size
  73.  
  74.    void read(sos_Offset o, unsigned size, void* data) const;
  75.    void write(sos_Offset o, unsigned size, void* data) const;
  76.    void copy(sos_Offset o1, unsigned size, sos_Container c2, sos_Offset o2) const;
  77.    int equal(sos_Offset o1, unsigned size, sos_Container c2, sos_Offset o2) const;
  78.    int hash_value(sos_Offset o1, unsigned size) const;
  79.  
  80.    sos_Object root_object () const;
  81. };
  82.  
  83. // ******************************************************************************
  84.  
  85. extern const sos_Container TEMP_CONTAINER;
  86. extern const sos_Container ROOT_CONTAINER;
  87. extern const sos_Container UNUSED_CONTAINER;
  88.  
  89. extern const sos_Offset ROOT_OFFSET;
  90.  
  91. // ******************************************************************************
  92.  
  93. class sos_Container_set {
  94.  
  95. //friend sos_Open_result op(int, const sos_Container_set& ,const sos_Container_set&, sos_Sync_mode);
  96. //friend void cl(int, const sos_Container_set&, const sos_Container_set&);
  97.  
  98. public:
  99.    unsigned card() const { return n; } 
  100.    // sos_Container_set(const sos_Container_set&);
  101.    // copy constructor do not work correectly for the gnu compiler
  102.    sos_Container_set();
  103.    ~sos_Container_set();
  104.    //sos_Container_set& operator=(const sos_Container_set&);
  105.    sos_Container_set& operator+=(sos_Container c);
  106.  
  107.    static sos_Container_set& open_containers(sos_Container_status); 
  108.    static sos_Open_result open(const sos_Container_set& rd, const sos_Container_set& wr, sos_Sync_mode);
  109.    sos_Open_result open(sos_Access_mode, sos_Sync_mode) const;
  110.    void close() const;
  111.  
  112.    static sos_Open_result op(int, const sos_Container_set& ,const sos_Container_set&, sos_Sync_mode);
  113.    static void cl(int, const sos_Container_set&, const sos_Container_set&);
  114.  
  115.    void commit() const;
  116.    void reset() const;
  117.  
  118.    sos_Container_cursor open_cursor() const;
  119.    void close_cursor (sos_Container_cursor&) const;
  120.    int to_succ (sos_Container_cursor&) const;
  121.    int is_valid(sos_Container_cursor) const;
  122.    sos_Container get (sos_Container_cursor) const;
  123.  
  124. private:
  125.    int* s;
  126.    unsigned n,size;
  127. };
  128.  
  129. // ****************************** sos_Container_cursor ****************************** 
  130. class sos_Container_cursor {
  131.    friend class sos_Container_set;
  132.  
  133.    public:
  134.       int is_valid() const { return (idx >= 0); }
  135.    private:
  136.       int idx;
  137. };
  138.  
  139. // ****************************** cnt_iterate ****************************** 
  140.  
  141. #define cnt_iterate(s, e) \
  142. {sos_Container_cursor _cnt_cursor = s.open_cursor(); \
  143. for (int _cnt_valid = s.is_valid (_cnt_cursor); \
  144.       _cnt_valid; \
  145.       _cnt_valid = s.to_succ (_cnt_cursor)) \
  146.  { e = s.get(_cnt_cursor);
  147.  
  148. #define cnt_iterate_end(s, e) } s.close_cursor (_cnt_cursor);}
  149.  
  150. #endif PSMH
  151.